//
//  TouchView.m
//  UI29_Block
//
//  Created by dllo on 16/1/21.
//  Copyright © 2016年 刘旺辉. All rights reserved.
//

#import "TouchView.h"

@interface TouchView ()
@property (strong, nonatomic) IBOutlet UIView *view;
@property (nonatomic, copy) void (^block)(TouchView *);
@property (nonatomic, copy) void (^deleteBtnHandle)(UIButton *);
@property (nonatomic, copy) void (^editBtnHandle)(UIButton *);
@end

@implementation TouchView

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        
        [[NSBundle mainBundle] loadNibNamed:@"TouchView" owner:self options:nil];
        self.view.frame = self.bounds;
        [self addSubview:self.view];
        
    }
    return self;
}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    // 点击之后, 调用block
    self.block(self);
    
}

/** 实现带block参数的方法 */
- (void)viewDidClick:(void (^)(TouchView *))block {
    
    self.block = block;
    
}


- (void)buttonHandle:(void (^)(UIButton *deleteBtn))block {
    self.deleteBtnHandle = block;
}

/** 点击删除button */
- (IBAction)handleButtonAction:(id)sender {
    
    self.deleteBtnHandle((UIButton *)sender);
}

/** 点击编辑button */
- (IBAction)handleEditAction:(id)sender {
    
    self.editBtnHandle((UIButton *)sender);
    //self.deleteBtnHandle((UIButton *)sender);
}

- (void)editBtnHandle:(void (^)(UIButton *editBtn))block1 deleBtnhandle:(void (^)(UIButton *deleBtn))block2 {
    self.editBtnHandle = block1;
    self.deleteBtnHandle = block2;
    
}

@end
